/**********************************************************
 * Validator.java.java 
 * Created by Ashutosh
 * Last modified Date: Sep 18, 2008 11:07:50 AM by Ashutosh
 * Revision: <svn revision #> 
 * Version : 0.1
 * Copyright (c) 2008 - 2009 cyberThink Infotech Pvt. Ltd., All rights reserved.
 **********************************************************/

package com.printeverywhere.util;

import org.apache.log4j.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * The Class Validator.
 */
public class Validator {
	
	/** Logger for this class. */
	private static final Logger logger = Logger.getLogger(Validator.class);

	/**
	 * Checks if is mail address.
	 * 
	 * @param email the email
	 * 
	 * @return true, if is mail address
	 */
	public static boolean isMailAddress(String email) {
		if (logger.isDebugEnabled()) {
			logger.debug("isMailAddress(String) - start"); //$NON-NLS-1$
		}

		//Set the email pattern string
	      Pattern p = Pattern.compile("\b(^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-])+(\\.[A-Za-z0-9-]+)*((\\.[A-Za-z0-9]{2,})|(\\.[A-Za-z0-9]{2,}\\.[A-Za-z0-9]{2,}))$)\b");

	      //Match the given string with the pattern
	      Matcher m = p.matcher(email);

	      //check whether match is found
		boolean returnboolean = m.matches();
		if (logger.isDebugEnabled()) {
			logger.debug("isMailAddress(String) - end"); //$NON-NLS-1$
		}
	      return returnboolean;
	}
}